/* xx28.10.1cim.p - Gen CIM for modifing ERS Option
   Created By: Hayden (2015EE) 2016-06-15
   
   Purpose: Gen CIM for modifing ERS Option
   Runtime: 2015EE
   Cimload: 2015EE
   
   Upgrade Step:
     1. run program in 2015EE generate *.cim files
     2. doing cimload in each domain by cim file prefix
*/

{us/mf/mfdtitle.i}

def var outname as char format 'x(16)' init '28.10.1-ers' label 'Out File'.
def var outfile as char format 'x(24)'.

outfile = global_domain + '-' + outname + '.cim'.

repeat:
  disp 'Gen CIM for modifing ERS Option' skip
       'Runtime: 2015EE' skip
       'Cimload: 2015EE' skip(1)
       'Upgrade Step:' skip
       '  1. run program in 2015EE generate *.cim files' skip
       '  2. doing cimload in each domain by cim file prefix' skip(1)
       outname colon 14 '.cim' space(2) outfile no-label view-as text skip
  with frame a width 80 side-label.
  
  prompt-for outname with frame a editing:
    if frame-field = 'outname' then do:
      if input outname <> '' then do:
        disp global_domain + '-' + input outname + '.cim' @ outfile with frame a.
      end.
      else do:
        disp '' @ outfile with frame a.
      end.
    end.
    status input.
    readkey.
    apply lastkey.
  end.
  
  outname = input outname.
  
  if outname = '' then do:
    message 'Error: Please enter all Filenames'.
    next.
  end.
  
  outfile = global_domain + '-' + outname + '.cim'.
  
  os-delete value(outfile).
  output to value(outfile).
  
  for each ers_mstr where ers_domain = global_domain no-lock:
    def var v_vend as char.
    v_vend = trim(ers_vend).
    
    put '@@batchload apersmt.p' skip.
    put unformatted '"' v_vend '" "' ers_site '" "' ers_part '"' skip.
    
    if v_vend <> '' and upper(substring(v_vend, length(v_vend))) = 'D' then do:
      put unformatted 2.
    end.
    else do:
      put unformatted 3.
    end.
    
    put ' -' skip.
    put '@@end' skip.
  end.
  
  output close.
  
  message 'Completed!'.
  
end.